#include "Common.hpp"
#include "TcpServer.hpp"
// #include "Dict.hpp"
#include "Command.hpp"
void Usage(std::string proc)
{
    std::cerr << "Usage: " << proc << " port" << std::endl;
}

// 远程命令执行的功能！
// ./tcpserver port
int main(int argv, char *argc[])
{
    if(argv != 2)
    {
        Usage(argc[0]);

        exit(USAGE_ERR);
    }

    uint16_t port = std::stoi(argc[1]);

    Enable_Console_Log_Strategy();

    //1. 命令模块
    Command cmd;

    // std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port,
    //     std::bind(&Command::Execute, &cmd, std::placeholders::_1, std::placeholders::_2));
    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port, [&cmd](const std::string &command,  InetAddr &addr){
        return cmd.Execute(command, addr);
    });

    // 1. 翻译模块
    // Dict d;
    // d.LoadDict();
    
    // std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port, [&d](const std::string &word, InetAddr &addr){
    //     return d.Translate(word, addr);
    // });

    tsvr->Init();
    tsvr->Run();
    return 0;
}